package com.dmzc.stage2.chapter19;

import java.util.concurrent.TimeUnit;

public class TestFuture {
    public static void main(String[] args) throws InterruptedException {
//        FutureService<Void,Void>service=FutureService.newService();
//        Future<?>future=service.submit(()->{
//            try {
//                TimeUnit.SECONDS.sleep(10);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            System.out.println("i am finish done");
//        });
//        future.get();


//        FutureService<String,Integer>service=FutureService.newService();
//        Future<Integer>future=service.submit(input->{
//            try {
//                TimeUnit.SECONDS.sleep(10);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            System.out.println("i am finish done");
//            return input.length();
//            },"hello");
//        System.out.println(future.get());

        FutureService<String,Integer>service=FutureService.newService();
        Future<Integer>future=service.submit(input->{
            try {
                TimeUnit.SECONDS.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("i am finish done");
            return input.length();
        },"hello",System.out::println);
        System.out.println(future.get());


    }
}
